<script type="text/javascript">
	validation_kurs = null;
	kurslist_createimageWindows = null;
	$(document).ready(function () {
		/* DECLARATION VARIABLE */
		/* General Variable */
		var theme = 'fresh';
		var kurslist_source;
		var kurslist_dataAdapter;

		/* Area and Field Variable */
		var kurslist_menu = $("#kurslist_menu");
		var kurslist_content = $("#kurslist_content");
		var kurslist_expander = $("#kurslist_expander");
		var kurslist_form = $("#kurslist_form");
		var kurslist_gridview = $("#kurslist_gridview");
		var kurslist_search_textfield = $("#kurslist_search_textfield");
		var kurslist_searchbutton = $("#kurslist_searchbutton");
		var kurslist_addbutton = $("#kurslist_addbutton");
		var kurslist_editbutton = $("#kurslist_editbutton");
		var kurslist_deletebutton = $("#kurslist_deletebutton");
		var kurslist_resetbutton = $("#kurslist_resetbutton");
		var kurslist_validasiwindow = $("#kurslist_validasiwindow");
		var kurslist_btnokValidasiWindow = $("#kurslist_btnokValidasiWindow");
		var kurslist_btnsaveValidasiWindow = $("#kurslist_btnsaveValidasiWindow");
		var kurslist_contentValidasiWindow = $("#kurslist_contentValidasiWindow");
		var kurslist_nomasukValidasiWindow = $("#kurslist_nomasukValidasiWindow");

		/* END DECLARATION VARIABEL */

		/* SET TYPE AND THEME */
		$('.field_input').addClass('jqx-input');
		$('.field_input').addClass('field');
		$('.field_input').addClass('jqx-rc-all');

		kurslist_menu.jqxMenu({ align: 'left', width: '600px', height: '27px', autoOpen: false, autoCloseOnMouseLeave: false, showTopLevelArrows: true, theme: theme });
		kurslist_menu.css('visibility', 'visible');
		kurslist_addbutton.jqxButton({ theme : theme, width : '70px', height : '18px' });
		kurslist_editbutton.jqxButton({ width : '70px' , height : '18px' ,theme : theme });
		kurslist_deletebutton.jqxButton({ width : '70px' , height : '18px' ,theme : theme });
		kurslist_searchbutton.jqxButton({ theme : theme, width : '70px', height : '18px' });
		kurslist_resetbutton.jqxButton({ theme : theme, width : '70px', height : '18px' });
		kurslist_btnokValidasiWindow.jqxButton({ theme : theme, width : 70, height : 25 });
		kurslist_btnsaveValidasiWindow.jqxButton({ theme : theme, width : 120, height : 25 });

		var kurslist_source = {
			id : 'id',
			datatype : "json",
			url : "<?php echo base_url(); ?>c_kurs/kurs_list",
			root : "results",
			datafields : [
				{ name : 'id' },
				{ name : 'matauang' },
				{ name : 'beli' },
				{ name : 'jual' },
				{ name : 'tanggal' }
			],
			beforeprocessing : function(data){
				kurslist_source.totalrecords = data[0].TotalRows;
			}
		}
		var kurslist_dataAdapter = new $.jqx.dataAdapter(kurslist_source);

		kurslist_gridview.jqxGrid({
			source : kurslist_dataAdapter,
			width : 600,
			theme : theme,
			pageable : true,
			autoheight : true,
			sortable : true,
			filterable : true,
			columnsresize : true,
			virtualmode : true,
			pagesize : 15,
			pagesizeoptions : [15],
			rendergridrows : function(){
				return kurslist_dataAdapter.records;
			},
			columns : [
				{text : 'Mata Uang', dataField : 'matauang', width : 100},
				{text : 'Beli', dataField : 'beli', width: 100},
				{text : 'Jual', dataField : 'jual', width: 100},
				{text : 'Tanggal', dataField : 'tanggal', width: 150}
			]
		});


		/* DECLARATION FUNCTION */
		function reset_form(){
		}
		function refresh_grid(){
			kurslist_gridview.jqxGrid('updatebounddata');
		}

		kurslist_addbutton.click(function(){
			$('#kurslist_content').empty();
			$('<img src="./images/loader.gif" style="margin:50px auto auto 390px;">').appendTo('#contents');
			$('#kurslist_content').load('index.php/c_kurs/kurs_addedit');
		});

		kurslist_editbutton.click(function(){
			var kurs_id = '';
			var rowindex = kurslist_gridview.jqxGrid('getselectedrowindex');
			var data_record = kurslist_gridview.jqxGrid('getrowdata', rowindex);
			if(data_record !== null){
				kurs_id = data_record.id;
				$('#kurslist_content').empty();
				$('<img src="./images/loader.gif" style="margin:50px auto auto 390px;">').appendTo('#contents');
				$('#kurslist_content').load('index.php/c_kurs/kurs_addedit/'+kurs_id);
			}else{
				alert("Pilih salah satu field yang ingin diubah");
			}
		});

		kurslist_searchbutton.click(function(){
			var search_text = kurslist_search_textfield.val();
			kurslist_source['url'] = "index.php/c_kurs/kurs_list?query=" + search_text;
			kurslist_gridview.jqxGrid('gotopage',0);
			kurslist_dataAdapter.dataBind();
		});
		kurslist_resetbutton.click(function(){
			kurslist_search_textfield.val("");
			kurslist_source['url'] = "index.php/c_kurs/kurs_list/";
			kurslist_gridview.jqxGrid('gotopage',0);
			kurslist_dataAdapter.dataBind();
		});

		kurslist_deletebutton.click(function(){

			var rowindex = kurslist_gridview.jqxGrid('getselectedrowindex');
			var data_record = kurslist_gridview.jqxGrid('getrowdata', rowindex);
			if(data_record !== null){
			var kurs_id=data_record.id;

			if(window.confirm("Apakah anda yakin menghapus data ini ? ")){
				$(document).ready(function () {
					$.ajax({
						url : 'index.php/c_kurs/kurs_delete',
						type : 'POST',
						data : {
							id : kurs_id
						}, success : function(msg){
							var result = eval(msg);
							if(result == 1){
								$("#kurslist_gridview").jqxGrid('updatebounddata');
								alert("Data sukses dihapus");
							}else{
								alert("Data gagal dihapus");
							}
						}
					});

				});
			}
		}

		});

		function kurslist_view(event, type ,file){
			kurslist_createimageWindows(type ,file);
		}

		function kurslist_edit(event, id) {
			self.location='index.php/c_kurs/get_action&task=update/' + id;
		}

		function kurslist_validasi(event, row) {
			validation_permohonan(row);
		}

});
</script>
<style type="text/css">
	.field{
		height : 22px;
	}
</style>
	<!-- Begin one column window -->
<br class="clear"/>
<div class="header">
	<span><h1>KURS</h1></span>
</div>
<div id="kurslist_content">
	<div id="kurslist_menu">
		<div id='kurslist_addbutton' style="float:left;">
			<img style='float: left; margin: 0px;' src='./images/icons/add.png' />
			<div style='float: left; margin-left: 4px;'>Baru</div>
		</div>
		<div id='kurslist_editbutton' style="float:left;">
			<img style='float: left; margin: 0px;' src='./images/icons/page_edit.png' />
			<div style='float: left; margin-left: 4px;'>Ubah</div>
		</div>
		<div id='kurslist_deletebutton' style="float:left;">
			<img style='float: left; margin: 0px;' src='./images/icons/delete.png' />
			<div style='float: left; margin-left: 4px;'>Hapus</div>
		</div>
		<div style="float:left;">
			<input type="text" id="kurslist_search_textfield" class="field_input" style="height: 24px; width : 200px; background-color : #FFFFFF;">
		</div>
		<div id='kurslist_searchbutton' style="float:left;">
			<img style='float: left; margin: 0px;' src='./images/icons/search.gif' />
			<div style='float: left; margin-left: 4px;'>Cari</div>
		</div>
		<div id='kurslist_resetbutton' style="float:left;">
			<img style='float: left; margin: 0px;' src='./images/icons/table_refresh.png' />
			<div style='float: left; margin-left: 4px;'>Reset</div>
		</div>
	</div>
	<div id="kurslist_gridview"></div>
</div>